<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>JavaScript的冒泡和捕获 | Closure233</title><meta name="author" content="Closure233"><meta name="copyright" content="Closure233"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="JavaScript的冒泡和捕获JavaScript中的DOM事件模型包括冒泡和捕获，冒泡是事件从当前元素向上到祖先元素，捕获是从上到下达到目标元素。DOM 事件标准描述了事件传播的 3 个阶段：  捕获阶段（Capturing phase）—— 事件（从 Window）向下走近元素。  目标阶段（Target phase）—— 事件到达目标元素。  冒泡阶段（Bubbling phase）——">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript的冒泡和捕获">
<meta property="og:url" content="https://closure.gitee.io/2023/05/10/JavaScript%E7%9A%84%E5%86%92%E6%B3%A1%E5%92%8C%E6%8D%95%E8%8E%B7/index.html">
<meta property="og:site_name" content="Closure233">
<meta property="og:description" content="JavaScript的冒泡和捕获JavaScript中的DOM事件模型包括冒泡和捕获，冒泡是事件从当前元素向上到祖先元素，捕获是从上到下达到目标元素。DOM 事件标准描述了事件传播的 3 个阶段：  捕获阶段（Capturing phase）—— 事件（从 Window）向下走近元素。  目标阶段（Target phase）—— 事件到达目标元素。  冒泡阶段（Bubbling phase）——">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://closure.gitee.io/images/avatar.gif">
<meta property="article:published_time" content="2023-05-10T03:30:00.000Z">
<meta property="article:modified_time" content="2023-08-08T05:14:40.317Z">
<meta property="article:author" content="Closure233">
<meta property="article:tag" content="js">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://closure.gitee.io/images/avatar.gif"><link rel="shortcut icon" href="/images/moss.ico"><link rel="canonical" href="https://closure.gitee.io/2023/05/10/JavaScript%E7%9A%84%E5%86%92%E6%B3%A1%E5%92%8C%E6%8D%95%E8%8E%B7/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: true,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'JavaScript的冒泡和捕获',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-08-08 13:14:40'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/images/avatar.gif" onerror="onerror=null;src='/images/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">11</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">6</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">0</div></a></div><hr/></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background: url(/images/cover/cover1.jpg)"><nav id="nav"><span id="blog-info"><a href="/" title="Closure233"><span class="site-name">Closure233</span></a></span><div id="menus"><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">JavaScript的冒泡和捕获</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2023-05-10T03:30:00.000Z" title="Created 2023-05-10 11:30:00">2023-05-10</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2023-08-08T05:14:40.317Z" title="Updated 2023-08-08 13:14:40">2023-08-08</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="JavaScript的冒泡和捕获"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="JavaScript的冒泡和捕获"><a href="#JavaScript的冒泡和捕获" class="headerlink" title="JavaScript的冒泡和捕获"></a>JavaScript的冒泡和捕获</h1><p>JavaScript中的DOM事件模型包括冒泡和捕获，冒泡是事件从当前元素向上到祖先元素，捕获是从上到下达到目标元素。<a target="_blank" rel="noopener" href="http://www.w3.org/TR/DOM-Level-3-Events/">DOM 事件</a>标准描述了事件传播的 3 个阶段：</p>
<ol>
<li><p>捕获阶段（Capturing phase）—— 事件（从 Window）向下走近元素。</p>
</li>
<li><p>目标阶段（Target phase）—— 事件到达目标元素。</p>
</li>
<li><p>冒泡阶段（Bubbling phase）—— 事件从元素上开始冒泡。</p>
</li>
</ol>
<h2 id="冒泡"><a href="#冒泡" class="headerlink" title="冒泡"></a>冒泡</h2><p>冒泡（bubbling）是指js中一个元素上发生的一个事件，会触发该元素上的处理程序，然后向上运行父元素的处理程序，一直向上运行其祖先元素的处理程序。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;body onclick=“<span class="title function_">alert</span>(<span class="string">&#x27;body&#x27;</span>)”&gt;</span><br><span class="line">    <span class="language-xml"><span class="tag">&lt;<span class="name">div</span> <span class="attr">onclick</span>=<span class="string">“alert(</span>&#x27;<span class="attr">div</span>&#x27;)”&gt;</span></span></span><br><span class="line"><span class="language-xml">        <span class="tag">&lt;<span class="name">p</span> <span class="attr">onclick</span>=<span class="string">“alert(</span>&#x27;<span class="attr">p</span>&#x27;)”&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line">&lt;/body&gt;</span><br></pre></td></tr></table></figure>

<p>点击最内部的<code>&lt;p&gt;</code>会先<code>alert(&#39;p&#39;)</code>,然后向上<code>冒泡</code>，按顺序运行<code>alert(&#39;div&#39;)</code>和<code>alert(&#39;body&#39;)</code>。这个事件向上冒泡的过程称为“事件冒泡（bubbling）”，事件从内部元素向上“冒泡”到所有的父级元素，如同水中的气泡。</p>
<p>除了少数几个事件（如<code>focus</code>、<code>blur</code>、<code>media事件</code>、<code>mouseleave &amp; mouseenter</code>），<strong>几乎</strong>所有事件都会冒泡。</p>
<h2 id="event-target"><a href="#event-target" class="headerlink" title="event.target"></a>event.target</h2><p>程序可以通过<code>event.target</code>获取和访问触发冒泡的目标元素。</p>
<p><code>event.target</code>和<code>this(event.currentTarget)</code>的区别：</p>
<ul>
<li><p><code>event.target</code>——触发事件的目标元素，在冒泡过程中不会变化（即上述的<code>&lt;p&gt;</code>元素）</p>
</li>
<li><p><code>this(event.currentTarget)</code>——当前事件所在的元素，有正在运行的处理程序</p>
</li>
</ul>
<p><code>event.target</code>可能会等于<code>this</code>，如点击body元素，此时的<code>event.target</code>等于<code>this</code></p>
<h2 id="停止冒泡"><a href="#停止冒泡" class="headerlink" title="停止冒泡"></a>停止冒泡</h2><p>冒泡事件会从目标元素开始不断地向上冒泡，直到<code>document</code>对象，有些事件甚至会达到<code>window</code>。可以使用<code>event.stopPropagation()</code>方法停止冒泡。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;body onclick=<span class="string">&quot;alert(`the bubbling doesn&#x27;t reach here`)&quot;</span>&gt;</span><br><span class="line">  <span class="language-xml"><span class="tag">&lt;<span class="name">button</span> <span class="attr">onclick</span>=<span class="string">&quot;event.stopPropagation()&quot;</span>&gt;</span>Click me<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span></span><br><span class="line">&lt;/body&gt;</span><br></pre></td></tr></table></figure>

<p>当点击<code>button</code>时，不会触发<code>body</code>上的<code>onclick</code>事件。</p>
<h3 id="注意："><a href="#注意：" class="headerlink" title="注意："></a>注意：</h3><p><code>event.stopPropagation()</code>不会阻止当前元素上的所有冒泡事件，只会阻止<code>event.stopPropagation()</code>绑定冒泡事件；</p>
<p><code>event.stopImmediatePropagation()</code>会阻止当前元素所有的冒泡事件。</p>
<h2 id="捕获"><a href="#捕获" class="headerlink" title="捕获"></a>捕获</h2><p>程序可以通过设置监视器对事件进行捕获，需要将处理程序的<code>capture</code>选型设置为<code>true</code>:</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">element.<span class="title function_">addEvenListener</span>(..., &#123;<span class="attr">capture</span>: <span class="literal">true</span>&#125;);</span><br><span class="line"><span class="comment">// 或直接简写</span></span><br><span class="line">element.<span class="title function_">addEvenListener</span>(..., <span class="literal">true</span>);</span><br></pre></td></tr></table></figure>

<p><code>capture</code> 选项有两个可能的值：</p>
<ul>
<li>如果为 <code>false</code>（默认值），则在冒泡阶段设置处理程序。</li>
<li>如果为 <code>true</code>，则在捕获阶段设置处理程序。</li>
</ul>
<p>虽然事件传播形式上有 3 个阶段，但第 2 阶段（“目标阶段”：事件到达元素）没有被单独处理：捕获阶段和冒泡阶段的处理程序都在该阶段被触发。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&lt;form&gt;<span class="variable constant_">FORM</span></span><br><span class="line">  &lt;div&gt;<span class="variable constant_">DIV</span></span><br><span class="line">    &lt;p&gt;P&lt;/p&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line">&lt;/form&gt;</span><br><span class="line"></span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">  <span class="keyword">for</span>(<span class="keyword">let</span> elem <span class="keyword">of</span> <span class="variable language_">document</span>.<span class="title function_">querySelectorAll</span>(<span class="string">&#x27;*&#x27;</span>)) &#123;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">    elem.<span class="title function_">addEventListener</span>(<span class="string">&quot;click&quot;</span>, <span class="function"><span class="params">e</span> =&gt;</span> <span class="title function_">alert</span>(<span class="string">`Capturing: <span class="subst">$&#123;elem.tagName&#125;</span>`</span>), <span class="literal">true</span>);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">    elem.<span class="title function_">addEventListener</span>(<span class="string">&quot;click&quot;</span>, <span class="function"><span class="params">e</span> =&gt;</span> <span class="title function_">alert</span>(<span class="string">`Bubbling: <span class="subst">$&#123;elem.tagName&#125;</span>`</span>));</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">  &#125;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></span><br></pre></td></tr></table></figure>

<p>如果你点击了 <code>&lt;p&gt;</code>，那么顺序是：</p>
<ol>
<li><code>HTML</code> → <code>BODY</code> → <code>FORM</code> → <code>DIV</code>（捕获阶段，第一个监听器）；</li>
<li><code>P</code>（目标阶段，触发两次，因为我们设置了两个监听器：捕获和冒泡）；</li>
<li><code>DIV</code> → <code>FORM</code> → <code>BODY</code> → <code>HTML</code>（冒泡阶段，第二个监听器）。</li>
</ol>
<p>有一个属性 <code>event.eventPhase</code>，它告诉我们捕获事件的阶段数。但它很少被使用，因为我们通常是从处理程序中了解到它。 </p>
<h3 id="注意"><a href="#注意" class="headerlink" title="注意"></a>注意</h3><ul>
<li><p>移除监听器需要在事件的同一阶段使用<code>removeEventListener</code>；</p>
</li>
<li><p>同一元素的同一阶段的多个事件处理程序的运行顺序与创建顺序相同。</p>
</li>
</ul>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>冒泡和捕获为“事件委托”奠定了基础 —— 一种非常强大的事件处理模式</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a target="_blank" rel="noopener" href="https://gitee.com/closure233">Closure233</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="https://closure.gitee.io/2023/05/10/JavaScript%E7%9A%84%E5%86%92%E6%B3%A1%E5%92%8C%E6%8D%95%E8%8E%B7/">https://closure.gitee.io/2023/05/10/JavaScript%E7%9A%84%E5%86%92%E6%B3%A1%E5%92%8C%E6%8D%95%E8%8E%B7/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/js/">js</a></div><div class="post_share"><div class="social-share" data-image="/images/avatar.gif" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/05/14/%E5%B8%B8%E8%A7%81%E7%9A%84CSS%E5%B8%83%E5%B1%80%E5%8F%8A%E5%85%B6%E5%AE%9E%E7%8E%B0%E6%96%B9%E5%BC%8F/" title="常见的CSS布局及其实现方式"><div class="cover" style="background: url(/images/cover/cover1.jpg)"></div><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">常见的CSS布局及其实现方式</div></div></a></div><div class="next-post pull-right"><a href="/2023/05/08/JavaScript%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%92%8C%E9%9A%90%E5%BC%8F%E8%BD%AC%E6%8D%A2/" title="JavaScript的数据类型和隐式转换"><div class="cover" style="background: url(/images/cover/cover1.jpg)"></div><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">JavaScript的数据类型和隐式转换</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>Related Articles</span></div><div class="relatedPosts-list"><div><a href="/2023/05/08/JavaScript%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%92%8C%E9%9A%90%E5%BC%8F%E8%BD%AC%E6%8D%A2/" title="JavaScript的数据类型和隐式转换"><div class="cover" style="background: url(/images/cover/cover1.jpg)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-05-08</div><div class="title">JavaScript的数据类型和隐式转换</div></div></a></div><div><a href="/2023/05/20/JavaScript%E7%9A%84%E5%8E%9F%E5%9E%8B%E5%92%8C%E5%8E%9F%E5%9E%8B%E9%93%BE/" title="JavaScript的原型和原型链"><div class="cover" style="background: url(/images/cover/cover1.jpg)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-05-20</div><div class="title">JavaScript的原型和原型链</div></div></a></div><div><a href="/2023/07/14/JavaScript%E6%95%B0%E7%BB%84%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/" title="JavaScript数组常用方法"><div class="cover" style="background: url(/images/cover/cover1.jpg)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-07-14</div><div class="title">JavaScript数组常用方法</div></div></a></div><div><a href="/2023/08/04/JavaScript%E5%BC%82%E6%AD%A5%E7%BC%96%E7%A8%8B%E5%92%8CPromise/" title="JavaScript异步编程和Promise"><div class="cover" style="background: url(/images/cover/cover1.jpg)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-08-04</div><div class="title">JavaScript异步编程和Promise</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/images/avatar.gif" onerror="this.onerror=null;this.src='/images/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Closure233</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">11</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">6</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">0</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/catfish233"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#JavaScript%E7%9A%84%E5%86%92%E6%B3%A1%E5%92%8C%E6%8D%95%E8%8E%B7"><span class="toc-number">1.</span> <span class="toc-text">JavaScript的冒泡和捕获</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%86%92%E6%B3%A1"><span class="toc-number">1.1.</span> <span class="toc-text">冒泡</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#event-target"><span class="toc-number">1.2.</span> <span class="toc-text">event.target</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%81%9C%E6%AD%A2%E5%86%92%E6%B3%A1"><span class="toc-number">1.3.</span> <span class="toc-text">停止冒泡</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B3%A8%E6%84%8F%EF%BC%9A"><span class="toc-number">1.3.1.</span> <span class="toc-text">注意：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8D%95%E8%8E%B7"><span class="toc-number">1.4.</span> <span class="toc-text">捕获</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B3%A8%E6%84%8F"><span class="toc-number">1.4.1.</span> <span class="toc-text">注意</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">2.</span> <span class="toc-text">总结</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/08/08/Axios/" title="Axios"><div style="background: url(/images/cover/cover1.jpg)"></div></a><div class="content"><a class="title" href="/2023/08/08/Axios/" title="Axios">Axios</a><time datetime="2023-08-08T03:30:00.000Z" title="Created 2023-08-08 11:30:00">2023-08-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/08/04/Ajax%E8%AF%B7%E6%B1%82/" title="AJAX请求"><div style="background: url(/images/cover/cover1.jpg)"></div></a><div class="content"><a class="title" href="/2023/08/04/Ajax%E8%AF%B7%E6%B1%82/" title="AJAX请求">AJAX请求</a><time datetime="2023-08-03T16:12:00.000Z" title="Created 2023-08-04 00:12:00">2023-08-04</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/08/04/JavaScript%E5%BC%82%E6%AD%A5%E7%BC%96%E7%A8%8B%E5%92%8CPromise/" title="JavaScript异步编程和Promise"><div style="background: url(/images/cover/cover1.jpg)"></div></a><div class="content"><a class="title" href="/2023/08/04/JavaScript%E5%BC%82%E6%AD%A5%E7%BC%96%E7%A8%8B%E5%92%8CPromise/" title="JavaScript异步编程和Promise">JavaScript异步编程和Promise</a><time datetime="2023-08-03T16:12:00.000Z" title="Created 2023-08-04 00:12:00">2023-08-04</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/07/14/JavaScript%E6%95%B0%E7%BB%84%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/" title="JavaScript数组常用方法"><div style="background: url(/images/cover/cover1.jpg)"></div></a><div class="content"><a class="title" href="/2023/07/14/JavaScript%E6%95%B0%E7%BB%84%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/" title="JavaScript数组常用方法">JavaScript数组常用方法</a><time datetime="2023-07-14T07:45:00.000Z" title="Created 2023-07-14 15:45:00">2023-07-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/06/21/%E7%AE%80%E5%8D%95%E7%9A%84CSS%E6%95%88%E6%9E%9C%E5%AE%9E%E7%8E%B0/" title="简单的CSS效果实现"><div style="background: url(/images/cover/cover1.jpg)"></div></a><div class="content"><a class="title" href="/2023/06/21/%E7%AE%80%E5%8D%95%E7%9A%84CSS%E6%95%88%E6%9E%9C%E5%AE%9E%E7%8E%B0/" title="简单的CSS效果实现">简单的CSS效果实现</a><time datetime="2023-06-21T05:30:00.000Z" title="Created 2023-06-21 13:30:00">2023-06-21</time></div></div></div></div></div></div></main><footer id="footer" style="background: url(/images/cover/cover1.jpg)"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By Closure233</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>